<template>
  <div>
    <TopFilter ref="topPanel" :list="topFilterList" :cols="4" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable ref="table" height="210" columnsRef="jzyBrand" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" :datakey="'rows'" :onColumnsChange="columns => (this.columns = columns)">
    </FilterTable>
    <FilterTable
      ref="table"
      height="210"
      columnsRef="partAccessDiffIndex"
      :columns="columns1"
      :fetchapi="fetchApi1"
      :params="fetchParams1"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns1 = columns)"
    >
    </FilterTable>
    <div style="text-align:center">
      <el-button size="small" type="primary" icon="el-icon-plus" @click="achieve()">完成</el-button>
      <el-button size="small" @click="excel1()">盘盈导出</el-button>
      <el-button size="small" @click="excel2()">盘亏导出</el-button>
      <el-button size="small" @click="finish()">取消</el-button>
    </div>
    <BaseDialog :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <BrandModal :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { queryPartInventory, queryPartProfirInit, queryPartLossInit, achieve, excel1, excel2 } from '@/api/parts/access/diff';
import BrandModal from './tabs/brandModal';

export default {
  name: 'Brand',
  components: {
    BrandModal
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', edit: '编辑', show: '显示' };
    return {
      formData: {},
      topFilterList: this.createTopFilterList(),
      fetchParams: {},
      fetchParams1: {},
      visible: false,
      dialogTitle: '',
      fetchApi: queryPartProfirInit,
      fetchApi1: queryPartLossInit,
      columns: this.createTableColumns(),
      columns1: this.createTableColumns1(),
      handleType: ''
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '盘点单号',
          fieldName: 'inventoryNo',
          placeholder: '盘点单号',
          unitRender: () => {
            return (
              <dev>
                <el-button size="small" type="primary" onClick={() => this.searchInven()}>
                  搜索
                </el-button>
              </dev>
            );
          }
        },
        {
          type: 'INPUT',
          label: '经手人',
          fieldName: 'HANDLER',
          placeholder: '经手人'
        },
        {
          type: 'DATE',
          label: '盘点日期',
          fieldName: 'INVENTORY_DATE',
          placeholder: '盘点日期'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库',
          dataIndex: 'STORAGE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '库位代码',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '借进数量',
          dataIndex: 'BORROW_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '借出数量',
          dataIndex: 'LEND_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '实际库存',
          dataIndex: 'REAL_STOCK',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '清点数量',
          dataIndex: 'CHECK_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '盈亏数量',
          dataIndex: 'PROFIT_LOSS_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '盈亏金额',
          dataIndex: 'PROFIT_LOSS_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '成本单价',
          dataIndex: 'COST_PRICE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '当前库存',
          dataIndex: 'CURRENT_STOCK',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    createTableColumns1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库',
          dataIndex: 'STORAGE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '库位代码',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '借进数量',
          dataIndex: 'BORROW_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '借出数量',
          dataIndex: 'LEND_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '实际库存',
          dataIndex: 'REAL_STOCK',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '清点数量',
          dataIndex: 'CHECK_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '盈亏数量',
          dataIndex: 'PROFIT_LOSS_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '盈亏金额',
          dataIndex: 'PROFIT_LOSS_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '成本单价',
          dataIndex: 'COST_PRICE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '当前库存',
          dataIndex: 'CURRENT_STOCK',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    searchInven() {
      console.log(1);
      this.visible = true;
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    changeHandle(val) {
      this.fetchParams = val;
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}品牌`;
      this.visible = true;
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    async achieve() {
      this.$refs.topPanel.SUBMIT_FORM();
      let res = await achieve({
        inventoryNo: this.fetchParams.inventoryNo
      });
      console.log(res);
    },
    async excel1() {
      this.$refs.topPanel.SUBMIT_FORM();
      let res = await achieve({
        inventoryNo: this.fetchParams.inventoryNo
      });
      console.log(res);
    },
    async excel2() {
      this.$refs.topPanel.SUBMIT_FORM();
      let res = await achieve({
        inventoryNo: this.fetchParams.inventoryNo
      });
      console.log(res);
    }
  }
};
</script>

<style lang="less" scoped></style>
